﻿CREATE PROCEDURE [dbo].[sp_Map_Delete_Order]
	@OrderID INT,
	@AccountID VARCHAR(10),
	@PeroidYear VARCHAR(4),
	@PeroidMonth VARCHAR(2),
	@ZipIDs VARCHAR(MAX)
AS
	IF @OrderID = 0
	begin
	SELECT @OrderID = OrderID FROM Orders WHERE AccountID = @AccountID AND PeroidYear = @PeroidYear AND PeroidMonth = @PeroidMonth
	end
	IF (@ZipIDs <> '')
	BEGIN
	IF CHARINDEX(',', @ZipIDs) = 0
	BEGIN
	DELETE FROM OrderZip WHERE OrderID=@OrderID AND ZipID = @ZipIDs
	END
	ELSE
	BEGIN
	DELETE FROM OrderZip WHERE OrderID=@OrderID AND ZipID IN 
	(SELECT subcolstr FROM udf_CharlistToTable(@ZipIDs, ','))
	END
	END